<template>
	<view class="bg-white">
		<u-tabs :list="tabs" name="bname" :is-scroll="false" activeColor="var(--mainColor)" :current="current" @change="change"></u-tabs>
		<mescroll-body ref="mescrollRef" :down="downOption" @init="mescrollInit" @down="downCallback" @up="upCallback">
			<view class="u-m-x-30" >
				<view class="flex  flex-column u-p-x-40 u-p-y-30 u-m-t-30 rounded-10 box-shadow bg-white" v-for="(item,index) in list" :key="index">
					<view class="flex justify-between">
						<text class="" style="width: 380rpx;line-height: 36rpx;">{{item.remark}}</text>
						<text>{{item.createtime}}</text>
						<!-- <text class="u-m-t-10">{{item.num}}元</text> -->
					</view>
					<view class="flex justify-between">
						<text class="u-m-t-10">{{ current == 0 ? item.num + '元' : item.num }}</text>
						<text class="u-m-t-10 text-greey">余额 {{item.balance}}</text>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import { MineCenterApi } from '@/api/serves.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				downOption:{
					textColor: '#333'
				},
				list: [],
				current:0,
				tabs: [
					{
						"bkey": "1",
						"bname": "余额"
					},
					{
						"bkey": "3",
						"bname": "贡献值"
					},
					{
						"bkey": "5",
						"bname": "权益值"
					}
				],
			}
		},
		onLoad(options) {
			this.current = options.current
		},
		methods: {
			// 下拉刷新回掉
			downCallback() {
				this.mescroll.resetUpScroll() 
			},
			// 上拉加载
			upCallback(page) {
				MineCenterApi.Ccdetails({type: this.tabs[this.current].bkey, page: page.num}).then(res=> {
					console.log('账户明细', res);
					if(res.code == 1){
						let result = res.data
						if(page.num == 1) this.list = []; //如果是第一页需手动制空列表
						this.list = this.list.concat(result); //追加新数据
						this.mescroll.endByPage(result.length, result.totalpage)
					}else {
						this.$toast(res.msg)
						this.mescroll.endErr()
					}
				})
			},
			change(index) {
				console.log(index);
				if(this.current == index) return 
				this.current = index
				this.mescroll.resetUpScroll() 
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>
